// 第 3 步：补充接口声明

// step 1:
// 在 tcp_socket.h 中写出必要的 #pragma once、依赖头文件、命名空间、以及 TCPBufferSize 常量。此时暂不定义结构体。
#pragma once

#include <cstddef>
#include <functional>
#include <string>
#include <vector>
#include "time_utils.h"
#include "logging.h"

namespace Common {
constexpr size_t TCPBufferSize = 64 * 1024 * 1024;

// step 2:
// 构造函数需要接收 Logger&，初始化收发缓冲区；还要显式禁止默认构造、拷贝/移动
struct TCPSocket {
  explicit TCPSocket(Logger &logger)
      : logger_(logger) {
    outbound_data_.resize(TCPBufferSize);
    inbound_data_.resize(TCPBufferSize);
  }

  // step 3
  // 在头文件中声明三个核心接口：connect、sendAndRecv、send，并加上注释说明职责
  auto connect(const std::string &ip, const std::string &iface, int port, bool is_listening);
  auto sendAndRecv() noexcept;
  auto send(const void *data, size_t len) noexcept;

  TCPSocket() = delete;
  TCPSocket(const TCPSocket &) = delete;
  TCPSocket(const TCPSocket &&) = delete;
  TCPSocket &operator=(const TCPSocket &) = delete;
  TCPSocket &operator=(const TCPSocket &&) = delete;

  int socket_fd_ = -1;
  std::vector<char> outbound_data_;
  size_t next_send_valid_index_ = 0;
  std::vector<char> inbound_data_;
  size_t next_rcv_valid_index_ = 0;
  struct sockaddr_in socket_attrib_{};
  std::function<void(TCPSocket *s, Nanos rx_time)> recv_callback_ = nullptr;
  std::string time_str_;
  Logger &logger_;
};

}  // namespace Common